package cn.gok.day3;

import java.util.Scanner;

/**
 * @ClassName Person
 * @Description TODO
 * @Author HP
 * @Date 19:02 2022/7/6
 * @Version 1.0
 *
 * 1人的结婚
 * 编写Person类,name,sex,age,isMarried(是否已婚)属性私有，getset公开，全构造函数。
 * 增加静态方法
 * public static boolean marryWith(Person p1,Person p2){1/工具类方法，执行p1和p2的结婚
 * /返回是否结婚成功
 * 1/1都要未婚
 * 1/2要异性
 * //3男生到达20岁，女生到达19岁}
 * 2 Person类中，增加方法public void study (String school) ;l/显示 xxx在xxxx学校学习。
 * 在main中，创建该类一个匿名内部类对象，重写study方法，并输入学习的时间，显示xxxx在xxx学校学习了几年。
 **/
public class Person {
    private String name;
    private String sex;
    private int age;
    private boolean isMarried;
    private Scanner scanner=new Scanner(System.in);


    public Person() {
    }
    public void study (String school){
        System.out.println(this.name+"在"+school+"学习");
    }
    public Person(String name, String sex, int age, boolean isMarried) {
        this.name = name;
//        判断输入的性别是否正确
        setSex(sex);
        this.age = age;
        this.isMarried = isMarried;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        if(sex.equals("男")||sex.equals("女")){
            this.sex = sex;
        }else {
            System.out.println(name+"的性别描述不符合规范，请重新输入：(提示：男 / 女)");
            sex=scanner.next();
            this.sex = sex;
            setSex(sex);
        }
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public boolean getIsMarried() {
        return isMarried;
    }

    public void setIsMarried(boolean isMarried) {
        this.isMarried = isMarried;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                ", isMarried='" + isMarried + '\'' +
                '}';
    }
}
